# name : ggplot2 waterfall template
# key : ggplot2.waterfall.template
# key : waterfall.template#ggplot2
# contributor: Shuguang Sun
# --
waterfalldt

ggplot(waterfalldt, aes(x = reorder(as.factor(SUBJID), desc(suvmaxpct_best)), y = suvmaxpct_best)) +
  geom_bar(stat = "identity", aes(fill = ARM)) +
  geom_text(aes(y = labely, label = labelbaseline), size = 3) +
  geom_text(aes(y = labelorr, label = orr3)) +
  ## geom_label(aes(label = labeltext), size = 2.5) +
  geom_hline(yintercept = -30, col = "#999999", linetype = "longdash", lwd = 1) +
  ## geom_point(data=swimlane_point, size = 5, # Use df.shapes to add reponse points
  ##            aes(id, value,
  ##                colour=responseType, shape=responseType),
  ##            na.rm = TRUE) +
  ## coord_flip() +
  scale_fill_manual(values = RColorBrewer::brewer.pal(7, "Pastel2"),
                    labels = c("5x10^5", "1x10^6", "3x10^6", "扩展:1x10^6")) +
  ## scale_colour_manual(values=RColorBrewer::brewer.pal(3, "Dark2")[1:3],
  ##                     labels = c("首次CR/PR", "首次新病灶", "首次PD")) + # Add colours
  ## scale_shape_manual(values=c(unicode[["arrow"]], # Add shapes
  ##                             unicode[["circle"]],
  ##                             unicode[["square"]]),
  ##                     labels = c("首次CR/PR", "首次新病灶", "首次PD")) +
  scale_y_continuous(breaks=c(-100, -30, 0, 100, 200)) + # Set time limits
  labs(fill="剂量组", colour="缓解情况", shape="缓解情况",
       x="受试者编号", y="SUV MAX相对基线变化最佳百分比"
       ## title="Swimmer Plot"
       ) +
  theme_ipsum_ps(
    ## base_family = font_rc,
    axis_title_just = "c",
    axis_title_size = 11.5,
    ## grid = "X",
    grid = FALSE
    ## axis_title_family = font_rc
  )+
  theme(legend.position = 'bottom', legend.box = "vertical",
        axis.text.x = element_text(angle = 45, vjust = 0.5)
        legend.key.size=unit(0.5, "cm"),
        legend.text=element_text(size=8),
        legend.title=element_text(size=8),
        legend.spacing=unit(0.05, "lines"))
